class Comment < ActiveRecord::Base
  belongs_to :post
  belongs_to :user
  has_ancestry
  
  def rate
    sum=0
    self.children.each do |c|
      sum += c.rating
    end
    if(self.children.length==0) 
      return nil
    else
      return sum/self.children.length 
    end
  end
  
end
